package com.zhiwang.planet.mvvm.model.entity.main

import android.os.Parcel
import android.os.Parcelable
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.google.gson.annotations.SerializedName
import com.zhiwang.planet.mvvm.model.entity.BindInfo
import com.zhiwang.planet.mvvm.model.entity.IndexActivity
import com.zhiwang.planet.mvvm.model.entity.User
import com.zhiwang.planet.mvvm.model.request.LoginRequest
import com.zhiwang.planet.mvvm.viewmodel.my.CommonPlayedItemViewModel
import com.zhiwang.planet.ui.my.record.CommonItemData


data class Recommedation(var title: String, var description: String = "", var shouldRecommend: Boolean = false)

data class HomeRecommend(
        @SerializedName("name")
        var title: String?,
        @SerializedName("url_type")
        var type: Int,
        @SerializedName("url")
        var link: String?,
        @SerializedName("img")
        var iconUrl: String?) {
    override fun toString(): String {
        return "HomeRecommend(title=$title, type=$type, link=$link, iconUrl=$iconUrl)"
    }
}

data class AvatarResponse(var file_url: String)

data class Game(var name: String?, var url: String?)

data class MessageBody(var list: List<Message>, var count: Int)

data class Message(var id: String,
                   var content: String,
                   @SerializedName("update_at")
                   var date: String,
                   @SerializedName("is_read")
                   var isRead: Int,
                   @SerializedName("goldz")
                   var diamond: String,
                   @SerializedName("goldd")
                   var bean: String)

data class NotificationBody constructor(var list: List<Notification>, var count: Int)

data class Notification(var id: String,
                        var content: String,
                        var title: String,
                        @SerializedName("create_at")
                        var date: String,
                        var type: String,
                        @SerializedName("url")
                        var link: String,
                        @SerializedName("is_read")
                        var hasRead: Int)

class NotificationRequest constructor(var type: String) {

    companion object {
        fun notification() = NotificationRequest("0")

        fun message() = NotificationRequest("1")
    }

}

class SetReadRequest constructor(var type: String, var id: String) {

    companion object {

        fun create(type: String, id: String) = SetReadRequest(type, id)

        fun notification(id: String) = SetReadRequest("0", id)

        fun message(id: String) = SetReadRequest("1", id)

    }
}


class DeleteReadRequest constructor(var type: String) {

    companion object {
        fun notification() = DeleteReadRequest("0")

        fun message() = DeleteReadRequest("1")
    }
}

/**
 * userid: "1300115",
username: "萼禀",
avatar: "http://file.ji7.com/avatar/159097982138242.jpg",
xqlevel: "0",
gold_z: "27577485",
gold_d: "0",
cash_num: "2,757.75",
vip: [ ]
 */
data class UserInfo(
        @SerializedName("userid")
        var userId: String,
        @SerializedName("username")
        var userName: String,
        @SerializedName("xqlevel")
        var xqLevel: String,
        var avatar: String,
        var phone: String,
        @SerializedName("gold_z")
        var diamond: String,
        @SerializedName("gold_d")
        var bean: String,
        @SerializedName("cash_num")
        var balance: String,
        //vip 图标
        var vip: List<String>,

        var banner: List<Banner>)

data class UserBanner(var banners: List<Banner>)

data class Banner(var img: String, var url: String) {

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as Banner

        if (img != other.img) return false
        if (url != other.url) return false

        return true
    }

    override fun hashCode(): Int {
        var result = img.hashCode()
        result = 31 * result + url.hashCode()
        return result
    }
}

data class ActivityBody(var list: List<Activity>)

data class SystemNotificationBody(var list: List<SystemNotification>)

data class FeedBackBody(var list: List<FeedBack>)

/**
 *  "id": "34",
"title": "测试了蛋咖上了就",
"type": "10",
"start_time": "2020-06-05 11:06:39",
"end_time": "2020-06-30 11:06:39",
"url": "",
"img": "",
"sort": "0",
"act_status": "0",
"status": "10",
"create_at": "2020-06-05 11:07:05",
"update_at": "2020-06-08 14:57:24",
"content": "是的撒大所大所,是空的杰卡斯的回复说的分红开的服流量费流量费快乐番薯老地方乐山大佛落实落地附加上防守打法链接发了开始大力客服雷石对接防守多了防守打法建档立卡福利卡看了看分离式的可浪费",
"is_read": "0"
 */
class Activity(var id: String,
               var title: String,
               var content: String,
               var url: String,
               var img: String,
               @SerializedName("create_at")
               var date: String,
               @SerializedName("is_read")
               var hasRead: Int)

/**
 *        "id": "30",
"sort": "0",
"type": "0",
"title": "【公告】关于无尽征途下线时间调整的通知！",
"content": "1.提现10元起，首次免手续费，后续收取2%的手续费；\\n2.每日提现不超过3次，工作日24小时内到账；\\n3.微信以零钱方式直接到账，请不要取消关注公众号；\\n4.提现前请确认账户无误，因账户问题导致的损失自行承担！",
"status": "10",
"tips": "0",
"create_at": "2020-06-27",
"update_at": "2020-06-08 14:58:50",
"ways": "0",
"is_read": 1
 */
data class SystemNotification(var id: String,
                              var title: String,
                              var content: String,
                              var type: Int,
                              @SerializedName("create_at")
                              var date: String,
                              var time: String,
                              var url: String = "",
                              @SerializedName("start_time")
                              var starttime: String,
                              @SerializedName("end_time")
                              var endtime: String) {


    val transformedData: String
        get() = when (type) {
            1 -> starttime + "至" + endtime
            2 -> date
            3 -> time
            else -> date
        }
}


/**
 *   "id": "930629",
"sender": "1",
"receiver": "1300115",
"title": "建议管理回复",
"content": "是发送到发送到是副科级斯蒂芬哈萨克的福卡数据的返回黑色款放假少的会计法",
"status": "10",
"create_at": "2020-04-20 16:49:56",
"update_at": "2020-04-20 16:52:26",
"advice_id": "51",
"goldz": "100",
"goldd": "10",
"reward_status": "20",
"is_read": 1
 */
data class FeedBack(var id: String = "",
                    var title: String = "",
                    var content: String = "",
                    var status: Int = 0,
                    var status_msg: String = "",
        //回复
                    var huifu: String = "",
                    @SerializedName("goldz")
                    var diamond: String = "0",
                    @SerializedName("goldd")
                    var bean: String = "0") : Parcelable {

    constructor(parcel: Parcel) : this(
            parcel.readString()!!,
            parcel.readString()!!,
            parcel.readString()!!,
            parcel.readInt(),
            parcel.readString()!!,
            parcel.readString()!!,
            parcel.readString()!!,
            parcel.readString()!!) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(id)
        parcel.writeString(title)
        parcel.writeString(content)
        parcel.writeInt(status)
        parcel.writeString(status_msg)
        parcel.writeString(huifu)
        parcel.writeString(diamond)
        parcel.writeString(bean)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<FeedBack> {
        override fun createFromParcel(parcel: Parcel): FeedBack {
            return FeedBack(parcel)
        }

        override fun newArray(size: Int): Array<FeedBack?> {
            return arrayOfNulls(size)
        }
    }

}

data class RegResponse(@SerializedName("is_bind") var isBind: Int)

data class QQ(var qq: String)

data class WxLoginResponse(var token: String)

data class WxBindBody(@SerializedName("code") var code: String, var token: String) {

    @SerializedName("deviceid")
    var imei: String = ""

    @SerializedName("os_version")
    var androidVersion: String = ""

    @SerializedName("versionname")
    var appVersionName: String = ""

    @SerializedName("wifi")
    var wifiName: String = ""

    @SerializedName("model")
    var deviceModel: String = ""

    fun addExtra(req: LoginRequest) {
        imei = req.imei

        androidVersion = req.androidVersion

        appVersionName = req.appVersionName

        wifiName = req.wifiName

        deviceModel = req.deviceModel
    }

}

data class XqTask(var id: String? = null,
                  @SerializedName("img")
                  var icon: String,
                  @SerializedName("cname")
                  var title: String,
                  var desc: String,
                  @SerializedName("url")
                  var link: String) {

    fun toViewModel() = CommonPlayedItemViewModel(icon, title, link)
}


/*
act :ping 进入游戏
act: end 退出游戏
 */
data class H5GameReq constructor(val gameid: String, val act: String)

data class H5GameRes constructor(val reward: String)

data class GameBody(var lists: List<GameTask>,
                    @SerializedName("inner_lists")
                    var prefList: List<GameTask>?)

/**
 * id: "2055973065",
uid: 1988067250,
pTime: 1596080593109,
channel: 13697,
name: "萌喵消消乐",
gameIcon: "http://img.m3guo.com/group2/M00/00/DC/wKgMHFxRnB2AEwq5AAIkf-NdRfU081.png"
},
 */

data class H5Record(val id: String, val uid: String, val pTime: String, val name: String, val gameIcon: String) {


    //1 empty  ; 2 more   ; 3 item
    var type = 0

}


data class H5HotGame(val name: String,
                     val id: String,
                     @SerializedName("icon")
                     val gameIcon: String,
                     val tag: String) {
    var type = 0
}

data class GameTask(
        @SerializedName("img")
        var icon: String,
        @SerializedName("cname")
        var title: String,
        @SerializedName("reward_gold")
        var reward: String,
        @SerializedName("url")
        var link: String,
        @SerializedName("cs")
        var tag: String,
        var status: Int,
        var surplus: String? = "") {

    fun disable(): Boolean = status == 20
}

data class TaskReq(var type: String?) {


    fun setTypeNew() {
        type = "shangxin"
    }

    fun setTypeHighReward() {
        type = "gaoe"
    }

    fun setTypeFast() {
        type = "mianshen"
    }

    fun setTypeJisu() {
        type = "jisushenhe"
    }
}

data class Avatar(var avatar_url: String, var id: String)

data class ExchangeListBody(var conf: List<BeanExChangeItem>)

data class BeanExChangeItem(

        @SerializedName("goods_icon")
        var iconUrl: String,
        @SerializedName("goods_type")
        var type: String,
        @SerializedName("goods_price")
        var price: String,
        @SerializedName("goods_value")
        var value: String,
        @SerializedName("vip_buff")
        var buffer: String,
        @SerializedName("final_gold")
        var finalValue: String)

data class WithDrawActivityInfo(
        @SerializedName("surplus")
        var withdrawTime: Int,
        var progress: List<Int>,
        var desc: List<String>,
        @SerializedName("on_off")
        var onShotWithDrawActive: Boolean
)

data class ImportantNotice(var show: Int, var title: String?, var content: String?)

data class ImeiBody(var imei: String)

data class EntertainBody(
        var rule: String,
        var mygame: List<MiniGame>, var allgame: List<MiniGame>)

data class MiniGame(
//        @SerializedName("game_id")
        var gameid: String,
//        @SerializedName("game_name")

        var gamename: String,
//        @SerializedName("game_icon_url_square")
        var icon: String,
        var profit: Int? = 0,
//        @SerializedName("type_tag")
        var tags: List<String>)

data class Mobile(var url: String, var icon: String, var name: String)

/**
 *
 *   "user_info": {
"userid": "3",
"username": "橡果3",
"avatar": "http://static.ji7.com/images/xqavatar.png",
"phone": "13247185523",
"gold_z": "0.00",
"revenue": "0.00",
"inviterid": ""
}
 */
@Entity(tableName = "User")
data class XgUserInfo(
        @PrimaryKey
        var userid: String,
        var username: String,
        var avatar: String,
        var phone: String,
        var gold_z: String,
        var revenue: String,
        var inviterid: String,
        @Embedded
        @SerializedName("bind")
        var bindInfo: BindInfo)

data class IndexData(var user_info: XgUserInfo)

data class Diamond(var id: String,
                   @SerializedName("userid")
                   var userId: String,
                   @SerializedName("reward")
                   var carat: String?,
                   @SerializedName("create_at")
                   var createTime: String)

//"create_at": "2019-01-11 16:19:36",
//"payment": "weixin",
//"payment_txt": "微信提现",
//"money": "100.00",
//"status": "0",
//"status_txt": "待审核"
data class WithDrawRecord(
        @SerializedName("create_at")
        var date: String,
        @SerializedName("payment")
        var type: String,//weixin ,alipay
        @SerializedName("payment_txt")
        var typeText: String,
        var money: String,
        var status: Int,
        @SerializedName("status_txt")
        var statusText: String,
        @SerializedName("status_msg")
        var failMsg: String,
        @SerializedName("time_desc")
        var timeDesc: String? = "",
        @SerializedName("date_desc")
        var dateDesc: String? = ""
) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as WithDrawRecord

        if (date != other.date) return false
        if (type != other.type) return false
        if (typeText != other.typeText) return false
        if (money != other.money) return false
        if (status != other.status) return false
        if (statusText != other.statusText) return false
        if (failMsg != other.failMsg) return false

        return true
    }

    override fun hashCode(): Int {
        var result = date.hashCode()
        result = 31 * result + type.hashCode()
        result = 31 * result + typeText.hashCode()
        result = 31 * result + money.hashCode()
        result = 31 * result + status
        result = 31 * result + statusText.hashCode()
        result = 31 * result + failMsg.hashCode()
        return result
    }
}


data class WithDrawRecordBody(
        @SerializedName("total")
        var total: Int,
        @SerializedName("list")
        var data: List<WithDrawRecord>,
        var hasmore: Int,
        var page: Int)

data class WithDrawBody(
        @SerializedName("gold_z")
        var rest: String,//剩余趣钻数
        var cost: String,//提现手续费，单位元
        @SerializedName("monty") //实际到账金额，单位：元
        var successNum: String)

data class ConsumptionRecordBody(
        @SerializedName("total")
        var total: String,
        @SerializedName("list")
        var recordList: List<ConsumptionRecord>,
        @SerializedName("page")
        var page: Int,
        @SerializedName("hasmore")
        var hasMore: Int,
        @SerializedName("gold_z")//趣钻数
        var diamondNumber: String?,
        @SerializedName("gold_d")//趣豆数（即灵力[原型图和设计图上还未更正]）
        var beanNumber: String?


)

data class ConsumptionRecord constructor(
        @SerializedName("number")
        var number: String,
        @SerializedName("cost_text")
        var costText: String,
        var type: Int,
        var date: String,
        var date_desc: String,
        var time_desc: String
) : CommonItemData() {
    override fun getItemTitle() = getTypeText()

    override fun getItemDate() = date

    override fun getItemContent() = if (number.toLong() >= 0) "+".plus(number) else number.toString()

    private fun getTypeText() = costText

    override fun time() = time_desc

    override fun date() = date_desc

    override fun hashCode(): Int {
        var result = number.hashCode()
        result = 31 * result + costText.hashCode()
        result = 31 * result + type
        result = 31 * result + date.hashCode()
        return result
    }


}

class UpdateCheck(@SerializedName("apk_version")
                  var version: Int = 0,
                  @SerializedName("apk_path")
                  var url: String,
                  /**
                   * 0可选更新，1强制更新
                   */
                  @SerializedName("apk_isforceupdate")
                  var forceUpdate: Int = 0,
                  @SerializedName("apk_md5")
                  var md5: String,
                  @SerializedName("apk_size")
                  var size: Long = 0,
                  @SerializedName("version_name")
                  var versionName: String?,
                  @SerializedName("version_log")
                  var updateLog: String? = "") : Parcelable {

    constructor(parcel: Parcel) : this(
            parcel.readInt(),
            parcel.readString(),
            parcel.readInt(),
            parcel.readString(),
            parcel.readLong(),
            parcel.readString(),
            parcel.readString()) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(version)
        parcel.writeString(url)
        parcel.writeInt(forceUpdate)
        parcel.writeString(md5)
        parcel.writeLong(size)
        parcel.writeString(versionName)
        parcel.writeString(updateLog)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<UpdateCheck> {
        override fun createFromParcel(parcel: Parcel): UpdateCheck {
            return UpdateCheck(parcel)
        }

        override fun newArray(size: Int): Array<UpdateCheck?> {
            return arrayOfNulls(size)
        }
    }


}

data class InviteInfo(@SerializedName("invite") var count: String,//星友人数
                      @SerializedName("gold_z") var num: String//趣钻数

)

data class WxBindCodeInfo(
        @SerializedName("bind_code")
        var bindCode: String,
        @SerializedName("wx_gzh")
        var officialAccount: String,//公众号,
        @SerializedName("ticket_url")
        var qrCodeUrl: String?

)

data class VipRecordModel(var list: List<VipRecordItem>, var hasNextPage: Int)

/**
 * "amount": "200.00",
"vip": "9",
"vip_txt": "SVIP",
"status": " 待支付",
"create_at": "2019-04-26 13:47:47"
 */
data class VipRecordItem(var amount: String,
                         var vip: String,
                         var vip_txt: String,
                         var status: String,
                         @SerializedName("create_at")
                         var createTime: String)

class EmptyBody constructor()


class DiamondBeanInfo(@SerializedName("gold_z")
                      var diamond: String,
                      @SerializedName("gold_d")
                      var bean: String)


data class ServiceQQ(@SerializedName("kefu_qq") var qq: String,


        //0 加群；1 加人
                     @SerializedName("add_type")
                     var type: Int,

        //0 直接拉起； 1 弹窗提示
                     @SerializedName("exec_type")
                     var execType: Int,

                     @SerializedName("display_qq_text")
                     var displayText: String,

                     @SerializedName("copy_qq_text")
                     var copyText: String,

                     @SerializedName("qq_group_key")
                     var groupKey: String,

                     @SerializedName("qq")
                     var singleQQ: String,

                     @SerializedName("full_uri")
                     var fullUri: String,

                     @SerializedName("use_full_uri")
                     var userFullUri: Boolean) {


    val showDialog: Boolean get() = execType == 1

}

data class GameItem(
        @SerializedName("img")
        var iconUrl: String? = "",
        var name: String? = "",
        var url: String? = "",
        @SerializedName("view_type")
        var fullScreen: Int)

data class TokenBody(var token: String)

data class BindBody(var bind: Int, var token: String, var openid: String)

data class TinyGameReward(@SerializedName("reward_gold_z")
                          var diamondRewardNum: String?,
                          @SerializedName("reward_gold_d")
                          var beanRewardNum: String?)


data class MiniGameToken(@SerializedName("xyx_logininfo")
                         var miniGameToken: String?)

data class TinyGameBody(
        @SerializedName("xyx_logininfo")
        var accountToken: String?,
        @SerializedName("xyx_list")
        var gameListBody: TinyGameListBody)


/**
 *  "xyx_logininfo": {
"id": "1",
"userid": "30007",
"data": "sdfdsfdsfdsfdsfds",
"create_at": "2019-10-08 14:29:44",
"update_at": "2019-10-08 14:29:44"
}
 */

data class TinyGameAccountInfo(
        @SerializedName("data")
        var accountToken: String?)

data class TinyGameListBody(
        @SerializedName("game_lists")
        var gameList: List<TinyGameInfo>)

/**
 *  "game_icon_url": "https://superman.cmcm.com/gamemoney/icon/kaixintiaoyitiao.png",
"game_icon_url_square": "https://superman.cmcm.com/gamemoney/squaticon/kaixintiaoyitiao.png",
"game_name": "开心跳一跳",
"slogan": "让小鸡跳到外太空",
"game_id": "kaixintiaoyitiao",
"type_tag": [
"益智",
"休闲",
"女生"
],
"h5Game": {
"h5_game_url": "https://superman.cmcm.com/h5game/funnyjump/v2019062401/index.html",
"gameLoadingImg": "https://superman.cmcm.com/gamemoney/loadpic/kaixintiaoyitiao.png"
}
 */

data class TinyGameInfo(
        @SerializedName("game_icon_url")
        var gameRoundIcon: String,
        @SerializedName("game_icon_url_square")
        var gameSquareIcon: String,
        @SerializedName("game_name")
        var gameName: String,
        @SerializedName("game_id")
        var gameId: String,
        @SerializedName("type_tag")
        var tags: List<String>,
        @SerializedName("h5Game")
        var tinyGameH5: TinyGameH5
)

data class TinyGameH5(
        @SerializedName("h5_game_url")
        var gameUrl: String,
        @SerializedName("gameLoadingImg")
        var gameLoadingImg: String)

data class DeviceQueryResult(var weixin: Int) {

    fun visible() = weixin == 1
}

data class IndexActivityBody(
        @SerializedName("index")
        var headerActivities: List<IndexActivity>,
        @SerializedName("ucenter")
        var bottomActivities: List<IndexActivity>,
        var vip_act_online: Boolean
)

data class VideoTaskCheck(
        @SerializedName("can_view")
        var completed: Int)

data class VideoClipTaskResult(
        @SerializedName("num_txt")
        var msg: String,
        @SerializedName("reward_gold")
        var reward: Int,
        @SerializedName("count_down")
        var countDownTime: Int,
        @SerializedName("max_num")
        var max: Int,
        @SerializedName("num")
        var num: Int) {

    val completed: Boolean get() = num == max
}